package ma.ensao.egicom.core.services.implementations;

import java.util.ArrayList;
import java.util.List;

import ma.ensao.egicom.core.dao.interfaces.CategoryDAO;
import ma.ensao.egicom.core.dto.CategoryDto;
import ma.ensao.egicom.core.model.Category;
import ma.ensao.egicom.core.services.interfaces.CategoryService;

import org.scub.foundation.framework.base.mapping.util.MapperDozerBean;
import org.scub.foundation.framework.base.messagesource.MessageSourceUtil;
import org.scub.foundation.framework.core.oval.validator.IntegrityValidator;

public class CategoryServiceImpl implements CategoryService {

    private MapperDozerBean mapperDozerBean;

    private IntegrityValidator integrityValidator;

    private MessageSourceUtil messageSourceUtil;

    private CategoryDAO categoryDao;

    @Override
    public List<CategoryDto> getAllCategories() {
        return mapCategoryList(categoryDao.findAll());
    }

    private List<CategoryDto> mapCategoryList(List<Category> categories) {
        final List<CategoryDto> categoryDto = new ArrayList<CategoryDto>();
        for (Category category : categories) {
            categoryDto.add((CategoryDto) mapperDozerBean.map(category, CategoryDto.class));
        }
        return categoryDto;
    }

    private CategoryDto mapCategory(Category category) {
        final CategoryDto categoryDto = mapperDozerBean.map(category, CategoryDto.class);
        return categoryDto;
    }

    public MapperDozerBean getMapperDozerBean() {
        return mapperDozerBean;
    }

    public MessageSourceUtil getMessageSourceUtil() {
        return messageSourceUtil;
    }

    public CategoryDAO getCategoryDao() {
        return categoryDao;
    }

    public void setMapperDozerBean(MapperDozerBean mapperDozerBean) {
        this.mapperDozerBean = mapperDozerBean;
    }

    public void setMessageSourceUtil(MessageSourceUtil messageSourceUtil) {
        this.messageSourceUtil = messageSourceUtil;
    }

    public void setCategoryDao(CategoryDAO categoryDao) {
        this.categoryDao = categoryDao;
    }

}
